package xeichengbishi;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
/**
 * Created by JiaJia on 2019/9/4 0004.
 */
public class Xiecheng03 {
    static int schedule(int m,int[] array) {
        long n=array.length;
        long right=1,left=0,res=0;
        for (int i = 0; i <n ; i++) {
            right+=array[i];
        }
        while (left<right){
            long middle=left+(right-left)/2;
            if (help(middle,array,m)){
                res=middle;
                right=middle;
            }else {
                left=middle+1;
            }
        }
        return (int)res;
    }
    static boolean help(long middle,int[] array,int m){
        long sum=0L,min=0L;
        for (int i = 0; i <array.length ; i++) {
            if (sum+array[i]>middle){
                min++;
                sum=0;
                sum+=array[i];
                if (array[i]>middle){
                    return false;
                }
            }else {
                sum+=array[i];
            }
        }
        return min<m;
    }
    /******************************结束写代码******************************/


    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int size  = in.nextInt();
        int[] array = new int[size];
        for(int i = 0; i < size; i++) {
            array[i] = in.nextInt();
        }
        int res = schedule(m,array);
        System.out.println(String.valueOf(res));
    }
}